//
//  Sqlite.m
//  cat
//
//  Created by imera on 16/3/19.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "Sqlite.h"

@implementation Sqlite

+ (sqlite3 *)getDb
{
    sqlite3 *db;
    
    NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    
    NSString *filePath = [doc stringByAppendingPathComponent:@"cat.sqlite"];
    
    const char *cfileName = filePath.UTF8String;
    
    int result = sqlite3_open(cfileName, &db);
    
    if (result == SQLITE_OK) {
//        NSLog(@"成功打开数据库");
        return db;
    }else{
//        NSLog(@"打开数据库失败");
        return nil;
    }
}

+ (BOOL)runWithSql:(NSString *)sql
{
    //创建表
    const char *sqlC = sql.UTF8String;
    
    char *err = NULL;
    
    int result = sqlite3_exec([self getDb], sqlC, nil, nil, &err);
    if (result == SQLITE_OK) {
        return YES;
    }else{
        return NO;
    }
}
@end
